package net.java.mediasystems.web.renderer;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import net.java.mediasystems.web.WebUtil;

import org.primefaces.component.fileupload.FileUploadRenderer;

/**
 * Own FileuploadRenderer-Implementation as Workaround to a bug with primefaces 4.0 and JSF 2.2.
 * <br/>
 * Changes in the Code for the Workaround:
 * <ul>
 * <li>
 * Implemented the Class "PatchedFileUploadRenderer"
 * </li>
 * <li>
 * Added a special Renderer-Config for the FileuploadRenderer in the faces-config.xml of the Webapp 
 * </li>
 * </ul>
 * 
 * 
 * For more information, read this thread and the answer: http://stackoverflow.com/a/19752138
 */
public class PatchedPrimefacesFileUploadRenderer extends FileUploadRenderer {
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void decode(FacesContext context, UIComponent component) {
		if (WebUtil.getFacesContext().getExternalContext().getRequestContentType().toLowerCase().startsWith("multipart/")) {
			super.decode(context, component);
		}
	}

}
